package com.blb.controller;


import com.blb.entity.Company;
import com.blb.service.ICompanyService;
import com.blb.utils.Response;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *企业账号管理
 * @author tb
 * @since 2020-05-20
 */
@Controller
@RequestMapping("/company")
public class CompanyController {

    @Resource
    ICompanyService companyService;

    @RequiresPermissions("deptno")
    @GetMapping("wtQiYeYongHu")
    public String enterpriseQiYeYongHu(){
        return "qiye/wt_qiyeyonghu";
    }
    @RequiresPermissions("deptno")
    @GetMapping("wtQiYeYongHuZi")
    public String enterpriseQiYeYongHuZi(){
        return "qiye/wt_qiyeyonghu_zi";
    }
    @RequiresPermissions("deptno")
    @ResponseBody
    @GetMapping("/pages")
    public Map<String, Object> getPages(@Param("start") Integer start, @Param("length") Integer length
            , @Param("companyRole") String companyRole, @Param("createUser") String createUser, @Param("companyName") String companyName,
                                        @Param("companyStatus") String companyStatus ){

        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("iTotalRecords",companyService.getCount());
        pageMap.put("iTotalDisplayRecords",companyService.getCount());
        pageMap.put("data",companyService.getPages(start, length, companyRole, createUser, companyName, companyStatus));
        return pageMap;

    }

    @RequiresPermissions("deptno")
    @ResponseBody
    @RequestMapping("/stop")
    public Response stop(@RequestBody(required=false) String id){

        System.out.println(id);
        Company company = new Company();
        company.setId(id);
        company.setCompanyStatus("已停用");
        companyService.updateById(company);
        return Response.success();
    }

    @RequiresPermissions("deptno")
    @ResponseBody
    @RequestMapping("/start")
    public Response start(@RequestBody(required=false) String id){
        System.out.println(id);
        Company company = new Company();
        company.setId(id);
        company.setCompanyStatus("已启用");
        companyService.updateById(company);
        return Response.success();
    }



}

